// ws_micro_shop/pages/cycle-purchase/cycle-purchase.js
const api = require('../../utils/api.js');
const app = getApp();
Page({
  data: {
    order_id: '',
    express_id: '',
    idx: 0,
    abnorData: {
      imgSrc: '/common/static/images/abnor-08.png',
      text: '暂无物流信息~',
    },
    is_comment: 0,
    list: [],
  },

  onLoad(options) {
    this.setData({
      order_id: options.order_id,
    });
    this.getInfo();
  },

  change() {
    this.getInfo();
  },

  getInfo() {
    let _this = this;
    let { order_id, idx } = _this.data;
    app.ws_micro_shoprequest({
      url: api.order.cycle_detail,
      data: {
        order_id: order_id,
        express_id: idx,
      },
      success: function(res) {
        if (res.code === 0) {
          _this.setData(res.data);
          _this.setData({
            express_id: res.data.express_id ? res.data.express_id : '',
            express_is_confirm: res.data.express_is_confirm
              ? res.data.express_is_confirm
              : '',
            is_comment: res.data.is_comment ? res.data.is_comment : '',
          });
        } else {
          // wx.showToast({
          //   title: res.msg,
          //   icon: 'none',
          // })
          _this.setData({
            express_id: false,
            list: [],
          });
        }
      },
    });
  },

  getLog(e) {
    this.setData({
      idx: e.currentTarget.dataset.idx,
    });
    this.getInfo();
  },

  onSunbmit() {
    let _this = this;
    let { express_id } = _this.data;

    wx.showModal({
      title: '提示',
      content: '是否确认收货',
      success(res) {
        if (res.confirm) {
          app.ws_micro_shoprequest({
            url: api.order.cycle_confirm,
            data: {
              express_id: express_id,
            },
            success: function(res) {
              if (res.code === 0) {
                wx.showToast({
                  title: res.msg,
                  icon: 'none',
                });
                _this.setData({
                  express_is_confirm: '1',
                });
              } else {
                wx.showToast({
                  title: res.msg,
                  icon: 'none',
                });
              }
            },
          });
        } else if (res.cancel) {
          return;
        }
      },
    });
  },

  pingjia() {
    let { order_id, idx } = this.data;
    app.util.navigateTo('/ws_micro_shop/pages/order-comment/order-comment', {
      id: order_id,
      entry: 'default',
      express_id: idx,
    });
  },
});
